<template>
  <div class="app-container">
    <el-row :gutter="24">
      <el-col :span="24" :xs="24">

        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="日程标题" prop="scheduleTitle">
            <el-input
              v-model="queryParams.scheduleTitle"
              placeholder="请输入日程标题"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="紧急程度" prop="scheduleLevel">
            <el-select v-model="queryParams.scheduleLevel" placeholder="请选择紧急程度" clearable>
              <el-option
                v-for="dict in dict.type.schedule_level"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="日程状态" prop="scheduleStatus">
            <el-select v-model="queryParams.scheduleStatus" placeholder="请选择日程状态" clearable>
              <el-option
                v-for="dict in dict.type.schedule_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-table :border="true" v-loading="loading" :data="scheduleList">
          <el-table-column label="日程名称" align="center" width="150" :show-overflow-tooltip="true" prop="scheduleTitle" />
          <el-table-column label="执行人" align="center" width="100" :show-overflow-tooltip="true" prop="nickName" />
          <el-table-column label="紧急程度" align="center" prop="scheduleLevel">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.schedule_level" :value="scope.row.scheduleLevel"/>
            </template>
          </el-table-column>
          <el-table-column label="开始时间/截至时间" align="center" prop="scheduleStart" width="300">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.scheduleStart, '{y}-{m}-{d} {h}:{i}') }}-{{ parseTime(scope.row.scheduleEnd, '{y}-{m}-{d} {h}:{i}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="日程状态" align="center" prop="scheduleStatus">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.schedule_status" :value="scope.row.scheduleStatus"/>
            </template>
          </el-table-column>
          <!--          <el-table-column label="备注" align="center" prop="remark" />-->
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <div v-if="scope.row.scheduleStatus=='2'||scope.row.scheduleStatus=='4'">


                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdate(scope.row)"
                  v-hasPermi="['userSchedule:schedule:edit']"
                >标记完成</el-button>
              </div>

              <div v-if="scope.row.scheduleStatus=='1'||scope.row.scheduleStatus=='3'">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-coffee-cup"
                  @click="getscheduleStatus(scope.row)"
                  v-hasPermi="['userSchedule:schedule:edit']"
                >查看总结</el-button>
              </div>

            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />


      </el-col>
    </el-row>

<!--    抽屉-->
    <el-drawer
      title="我是标题"
      :visible.sync="drawer"
      :with-header="false">
      <div style="padding: 15px">
        <div style="font-weight: 700">日程总结</div>
        <div v-html="scheduleConclusion">

        </div>
      </div>

    </el-drawer>


    <el-dialog :title="title" :destroy-on-close="true" :visible.sync="open" width="600px"  append-to-body>
      <el-form ref="form" :model="form" :rules="rules" >

        <el-form-item prop="scheduleConclusion">
            <wang-editor v-model="form.scheduleConclusion"></wang-editor>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { UserlistSchedule, getSchedule,doEdit } from "@/api/userSchedule/schedule";
export default {
  name: "Schedule",
  dicts: ['schedule_level', 'schedule_status'],
  data() {
    return {
      drawer: false,
      scheduleConclusion: '',
      //部门id
      deptId:null,
      // 遮罩层
      loading: true,

      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户日程表格数据
      scheduleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        deptId: null,
        scheduleTitle: null,
        scheduleLevel: null,
        scheduleStart: null,
        scheduleEnd: null,
        scheduleStatus: null,
        scheduleConclusion: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        scheduleConclusion: [
          { required: true, message: "日程总结不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户日程列表 */
    getList() {
      this.loading = true;
      UserlistSchedule(this.queryParams).then(response => {
        this.scheduleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getscheduleStatus(row){
      const scheduleId = row.scheduleId || this.ids
      getSchedule(scheduleId).then(response => {
        this.scheduleConclusion = response.data.scheduleConclusion;
        this.drawer = true;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        scheduleId: null,
        userId: null,
        deptId: null,
        scheduleTitle: null,
        scheduleLevel: null,
        scheduleStart: null,
        scheduleEnd: null,
        scheduleStatus: null,
        scheduleConclusion: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const scheduleId = row.scheduleId || this.ids
      getSchedule(scheduleId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "日程总结";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.scheduleId != null) {
            doEdit(this.form).then(response => {
              this.$modal.msgSuccess("提交成功");
              this.open = false;
              this.getList();
            });
          } else {

          }
        }
      });
    },
  }
};
</script>
